CentOS 7
Sponsored Link

Virt-Tools
2015/01/10
 
Install useful tools for virt management.
[1] Install virt tools.
[root@dlp ~]#
yum -y install libguestfs-tools virt-top
[2] "ls" a directory in a virtual machine.
[root@dlp ~]#
virt-ls -l -d centos7 /root

total 36
dr-xr-x---.  2 root root 4096 Jan  8 22:38 .
drwxr-xr-x. 17 root root 4096 Jan  8 22:36 ..
-rw-------.  1 root root   61 Jan  8 22:38 .bash_history
-rw-r--r--.  1 root root   18 Dec 29  2013 .bash_logout
-rw-r--r--.  1 root root  176 Dec 29  2013 .bash_profile
-rw-r--r--.  1 root root  176 Dec 29  2013 .bashrc
...
[3] "cat" a file in a virtual machine.
[root@dlp ~]#
virt-cat -d centos7 /etc/passwd

root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
...
[4] Edit a file in a virtual machine.
[root@dlp ~]#
virt-edit -d centos7 /etc/fstab

#
# /etc/fstab
# Created by anaconda on Thu Jan  8 13:20:43 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        1 1
UUID=537b215f-30a1-4e82-b05d-f480aa8e1034 /boot xfs     defaults        1 2
/dev/mapper/centos-swap swap                    swap    defaults        0 0
[5] Display disk usage in a virtual machine.
[root@dlp ~]#
virt-df -d centos7

Filesystem                     1K-blocks       Used  Available  Use%
centos7:/dev/sda1                 508588      72348     436240   15%
centos7:/dev/centos/root         8910848     779252    8131596    9%
[6] Mount a disk for a virtual machine.
[root@dlp ~]#
guestmount -d centos7 -i /media

[root@dlp ~]#
ll /media

total 32
lrwxrwxrwx.  1 root root    7 Jan  8 22:22 bin -> usr/bin
dr-xr-xr-x.  4 root root 4096 Jan  8 22:37 boot
drwxr-xr-x.  2 root root    6 Jan  8 22:20 dev
drwxr-xr-x. 74 root root 8192 Jan  8 22:36 etc
...
[7] Display the status of virtual machines.
[root@dlp ~]#
virt-top

virt-top 22:32:14 - x86_64 4/4CPU 2801MHz 11968MB
2 domains, 1 active, 1 running, 0 sleeping, 0 paused, 1 inactive D:0 O:0 X:0
CPU: 0.2%  Mem: 500 MB (500 MB by guests)

   ID S RDRQ WRRQ RXBY TXBY %CPU %MEM    TIME   NAME
    6 R    0    0            0.2  4.0   0:09.14 guestfs-o7nss1p3kxvyl1r5
    -                                           (centos7)
 
Tweet